<html>
    <head>
        <meta charset="utf-8">
        <title>绘制图元</title>
        <!-- leaflet的css样式 -->
        <link rel="stylesheet" href="../lib/leaflet.css" />
        <!-- leaflet的js库 -->
        <script type="text/javascript" src="../lib/leaflet-src.js"></script>

        <!-- 1) 添加leaflet.draw插件的引用 -->
        <link rel="stylesheet" type="text/css" href="../lib/plugins/draw/leaflet.draw.css"/>
        <script type="text/javascript" src="../lib/plugins/draw/leaflet.draw.js"></script>

        <!-- 地图容器样式 -->
        <style>
            #mapDiv{
                width: 100%;
                height: 100%;
            }
        </style>

        <script type="text/javascript">
            var map = null; 

            function init(){

                map = L.map("mapDiv", {
                    layers:[
                        L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png')
                    ],
                    center: [39.90,116.39],
                    zoom: 9,
                });

                //2)创建FeatureGroup，作为保存绘制的图元的容器
                var editableLayers = new L.FeatureGroup().addTo(map);

                //3)定义Draw控件的参数
                //  本例中设置featureGroup参数为刚刚创建的Feature图层
                var options = {
                    edit: {
                        featureGroup: editableLayers
                    }
                };

                //4)利用options创建Draw控件，添加到地图上
                var drawControl = new L.Control.Draw(options).addTo(map);
            }
        </script>
            
    </head>
    <body onload="init()">
        <!--地图的容器-->
        <div id="mapDiv"></div>
    </body>
</html>



